< previous page page_959 next page >

Page 959
7. Validation lists should be loaded by the Form_Load procedure.
8. The first section is the format of a positive number. The second section is the format of a negative number. The third section is the format of zero. Each section is separated by a semicolon (;).
Answers to Day 5 Exercises
1. Enter the following code inside your field's KeyPress event:
Sub FieldName_KeyPress(KeyAscii as Integer)
     If KeyAscii >26 then 'If anything other than a control code
          If Chr(KeyAscii) >= "a" and Chr(KeyAscii) <= "z" Then
               KeyAscii = KeyAscii - 32 ' Capitalize small letters
          Else
               KeyAscii = 0 ' No input from keyboard
          End if
     End if
End Sub
2. #,##0.00;-#,##0.00
3. Enter the following code into the cmdOK_Click event:
Sub cmdOK_Click ()

     Dim nOK as Integer ' Declare a test variable

     nOK = True

     If Len(Trim(txtDate)) = 0 then ' Check for entry (exclusive of spaces)
          MsgBox "Input is required in the txtDate field before this record                                                   _can be saved" ' Issue a message if no data is entered
          nOK = False 'Set test variable to False
          txtDate.SetFocus ' Place cursor in txtDate
     End if

     If nOK = True then
          Unload Me ' Exit form if data is entered
     End if
End sub
4. Enter the following code in the Form_Load event:
Sub Form_Load()

     'Load the combo box
     cboEmployees.AddItem "Smith"
     cboEmployees.AddItem "Andersen"
     cboEmployees.AddItem "Jones"
     cboEmployees.AddItem "Jackson"

End sub
You set the Sorted property of the combo box to True to alphabetically sort the information displayed in the combo box. This property can only be set at design time.

 
< previous page page_959 next page >

If you like this book, buy it!